package mess;

import javax.swing.plaf.ListUI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class LeeCode_89 {
    public static void main(String[] args) {
        System.out.println(grayCode(2));
    }

    private static List<Integer> grayCode(int n) {
        List<Integer> res = new ArrayList<>();
      /*  res.add(0);
        if (n == 0)
            return res;
        int now = 0;
        while (now < n){
            //翻转
            int size = res.size();
            int num =(int) Math.pow(2, now);
            List<Integer> temp = new ArrayList<>();
            for (int i = size - 1; i >= 0; i--) {
                temp.add(res.get(i) + num);
            }
            res.addAll(temp);
            now++;
        }
        return res;*/

        for (int i = 0; i < 1 << n; i++) {
            res.add(i ^ (i >> 1));
        }
        return res;
    }
}
